package com.zm.demo.core.concurrent;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadFactoryNct implements ThreadFactory {

    private String name;
    private final AtomicInteger threadNumber = new AtomicInteger(1);

    public ThreadFactoryNct(String name){
        this.name = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = Executors.defaultThreadFactory().newThread(r);
        t.setName(name + "-" + this.threadNumber.getAndIncrement());
        return t;
    }
}
